package Test26;

//初识内部类
//需求:写一个Javabean类描述汽车。
/*
    属性:汽车的品牌，车龄，颜色，发动机的品牌，使用年限。

    内部类的访问特点:
        内部类可以直接访问外部类的成员，包括私有
        外部类要访问内部类的成员，必须创建对象
*/
public class Test01 {
    public static void main(String[] args) {

        //创建对象
        Car c = new Car("宾利", 1, "黑色");
        c.show();
    }
}


class Car {
    private String carName;
    private int carAge;
    private String carColor;

    public Car() {
    }

    //外部类（汽车）
    public Car(String carName, int carAge, String carColor) {
        this.carName = carName;
        this.carAge = carAge;
        this.carColor = carColor;
    }

    public String getCarName() {
        return carName;
    }

    public void setCarName(String carName) {
        this.carName = carName;
    }

    public int getCarAge() {
        return carAge;
    }

    public void setCarAge(int carAge) {
        this.carAge = carAge;
    }

    public String getCarColor() {
        return carColor;
    }

    public void setCarColor(String carColor) {
        this.carColor = carColor;
    }

    public void show(Car this) {
        //是打印调用者车的名字：宾利
        System.out.println(this.carName);
        Engine e = new Engine();
        System.out.println(e.engineName);
    }

    //内部类（发动机）
    class Engine {
        private String engineName;
        private int engineAge;

        public Engine() {
        }

        public Engine(String engineName, int engineAge) {
            this.engineName = engineName;
            this.engineAge = engineAge;
        }

        public String getEngineName() {
            return engineName;
        }

        public void setEngineName(String engineName) {
            this.engineName = engineName;
        }

        public int getEngineAge() {
            return engineAge;
        }

        public void setEngineAge(int engineAge) {
            this.engineAge = engineAge;
        }

        public void show() {
            System.out.println(engineName);
            System.out.println(carName);
        }
    }
}
